﻿using UnityEngine;
using System.Collections;
using FairyGUI;

public abstract class BasePanel {
	protected GComponent view;

	public bool IsVisible { get; private set; }

	public virtual void Init()
	{
		UIPackage.AddPackage("Main"); 
		this.view = CreateView();
		this.view.Center();
	}

	public virtual void Show(params object[] para)
    {
		if (view != null)
		{
			GRoot.inst.AddChild(view);
			IsVisible = true;
		}
	}

	public virtual void Close()
	{
		if (view != null)
		{
			GRoot.inst.RemoveChild(view);
		}
		IsVisible = false;
	}

	public virtual void Dispose()
	{
		if (IsVisible)
		{
			Close();
		}

		if (view != null)
		{
			view.Dispose();
			view = null;
		}
	}

	protected abstract GComponent CreateView();
}
